<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>事件的冒泡传播</title>
    <style>
        *{
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        html, body{
            width: 100%;
            height: 100%;
            background: #cccccc;
            overflow: hidden;
        }
        #outer{
            margin: 20px auto;
            padding-top: 25px;
            width: 100px;
            height: 100px;
            background-color: red;
            cursor: pointer;
        }
        #inner{
            margin: 0 auto;
            width: 50px;
            height: 50px;
            background-color: blue;
            cursor: pointer;
        }
    </style>
</head>
<body>
    <div id="outer">
        <div id="inner"></div>
    </div>

</body>
<script>
    let outer = document.getElementById("outer");
    let inner = document.getElementById("inner");
/*    outer.onclick = function () {
        console.log("outer")
    };
    inner.onclick = function () {
        console.log("inner")
    }*/


    //当元素的某一个行为被触发,那么它所有的父级元素的相关行为都会被依次触发(由外到内)-->"事件捕获"
    //当元素的某一个行为被触发,那么它所有的父级元素的相关行为都会被依次触发(由内到外)-->"事件的冒泡传播"

//addEventListener 第三个参数代表是在捕获阶段触发还是在冒泡阶段触发回调函数
    //  true是捕获   false是冒泡
/*    outer.addEventListener("click", function () {
        console.log("捕获","outer")
    },true);
    inner.addEventListener("click", function () {
        console.log("捕获","inner")
    },true);
    outer.addEventListener("click", function () {
        console.log("冒泡","outer")
    },false);
    inner.addEventListener("click", function () {
        console.log("冒泡","inner")
    },false);*/

    outer.addEventListener("click", function (e) {
        console.log("冒泡","outer", e.target);
    },false);
    inner.addEventListener("click", function () {
        console.log("冒泡","inner")
    },false);

</script>
</html>